package org.jeecg.modules.wlhy.report.impl;

import cn.hutool.core.util.StrUtil;
import cn.hutool.json.JSONUtil;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.collections4.CollectionUtils;
import org.apache.commons.lang.StringUtils;
import org.jeecg.common.api.vo.Result;
import org.jeecg.common.constant.CommonConstant;
import org.jeecg.common.constant.enums.ReportPlatformEnum;
import org.jeecg.common.exception.JeecgBootException;
import org.jeecg.common.util.DateUtils;
import org.jeecg.common.util.LngLonUtil;
import org.jeecg.modules.third.jg.report.freight.information.constant.NxReportConstant;
import org.jeecg.modules.third.jg.report.freight.information.constant.enums.ReportDocTypeEnum;
import org.jeecg.modules.third.jg.report.freight.information.dto.AppInfoDTO;
import org.jeecg.modules.third.jg.report.freight.information.dto.DriverDTO;
import org.jeecg.modules.third.jg.report.freight.information.dto.VehicleDTO;
import org.jeecg.modules.third.jg.report.freight.information.dto.enterprise.EnterpriseDTO;
import org.jeecg.modules.third.jg.report.freight.information.dto.financial.FinancialDTO;
import org.jeecg.modules.third.jg.report.freight.information.dto.shippingnote.LocationDTO;
import org.jeecg.modules.third.jg.report.freight.information.dto.shippingnote.ShippingNoteDTO;
import org.jeecg.modules.third.jg.report.freight.information.model.R;
import org.jeecg.modules.third.jg.report.freight.information.service.HbReportPlatformService;
import org.jeecg.modules.wlhy.bill.entity.HyShippingNoteBill;
import org.jeecg.modules.wlhy.bill.service.IHyShippingNoteBillService;
import org.jeecg.modules.wlhy.company.entity.HyCompanyConfig;
import org.jeecg.modules.wlhy.enterprise.entity.HyEnterprise;
import org.jeecg.modules.wlhy.enterprise.service.IHyEnterpriseService;
import org.jeecg.modules.wlhy.hyconfig.entity.HyConfig;
import org.jeecg.modules.wlhy.hydriver.entity.HyDriver;
import org.jeecg.modules.wlhy.hydriver.entity.HyDriverReport;
import org.jeecg.modules.wlhy.hydriver.service.IHyDriverReportService;
import org.jeecg.modules.wlhy.hydriver.service.IHyDriverService;
import org.jeecg.modules.wlhy.hyvehicle.entity.HyVehicle;
import org.jeecg.modules.wlhy.hyvehicle.entity.HyVehicleReport;
import org.jeecg.modules.wlhy.hyvehicle.entity.HyVehicleType;
import org.jeecg.modules.wlhy.hyvehicle.service.IHyVehicleReportService;
import org.jeecg.modules.wlhy.hyvehicle.service.IHyVehicleService;
import org.jeecg.modules.wlhy.report.IReportService;
import org.jeecg.modules.wlhy.shipping.constant.ShippingPayStatus;
import org.jeecg.modules.wlhy.shipping.entity.HyShippingNote;
import org.jeecg.modules.wlhy.shipping.service.IHyShippingNoteService;
import org.jeecg.modules.wlhy.utils.HyCfgUtil;
import org.jeecg.modules.wlhy.utils.HyConfigUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.math.BigDecimal;
import java.util.Date;
import java.util.List;

@Service
@Slf4j
public class HbReportService implements IReportService {
    @Resource
    private BaseReportService baseReportService;

    @Resource
    private IHyEnterpriseService enterpriseService ;

    @Resource
    private IHyDriverService driverService;

    @Resource
    private IHyVehicleService vehicleService;

    @Resource
    private IHyDriverReportService hyDriverReportService;

    @Resource
    private IHyVehicleReportService vehicleReportService;

    @Resource
    private HbReportPlatformService hbReportPlatformService;

    @Autowired
    private IHyShippingNoteService hyShippingNoteService;

    @Autowired
    private IHyShippingNoteBillService hyShippingNoteBillService;

    @Override
    public ReportPlatformEnum getReportType() {
        return ReportPlatformEnum.REPORT_PLATFORM_HB;
    }

    @Override
    public void checkReport() {
        if(!HyCfgUtil.isUsed2("hebei_report")){
            throw new JeecgBootException("河北上报服务暂未开启,请联系管理。");
        }
    }


    @Override
    public Result setReportInfo(HyCompanyConfig hyCompanyConfig) {

        if (StrUtil.isEmpty(hyCompanyConfig.getReportUrl()) || StrUtil.isEmpty(hyCompanyConfig.getReportUsername())
                || StrUtil.isEmpty(hyCompanyConfig.getReportPassword()) || StrUtil.isEmpty(hyCompanyConfig.getReportPublickey())) {
            return Result.error("河北监管平台未配置参数!");
        }

        this.hbReportPlatformService.setReportInfo(hyCompanyConfig.getReportUrl(),
                hyCompanyConfig.getReportUsername(),
                hyCompanyConfig.getReportPassword(),
                hyCompanyConfig.getReportPublickey(),
                hyCompanyConfig.getReportAppid(),
                hyCompanyConfig.getReportAppkey(),
                hyCompanyConfig.getReportAppsender(),
                hyCompanyConfig.getReportApprelease());
        return Result.ok("设置成功");
    }

    @Override
    public Result reportShippingNote(HyShippingNote hyShippingNote) {
        Result result = this.checkDriverAndVehicle(hyShippingNote);
        if (!result.getCode().equals(CommonConstant.SC_OK_200)) {
            return result;
        }

        return this.uploadShippingNote(hyShippingNote);
    }

    @Override
    public Result reportCapitalFlow(HyShippingNote hyShippingNote) {
        Result result = this.checkDriverAndVehicle(hyShippingNote);
        if (!result.getCode().equals(CommonConstant.SC_OK_200)) {
            return result;
        }

        return this.uploadCapitalFlow(hyShippingNote.getId());
    }

    //上报运单和资金流水前，先确认司机、车辆的上传状态
    private Result checkDriverAndVehicle(HyShippingNote hyShippingNote) {

        String driverId = hyShippingNote.getDriverId();
        String vehicleId = hyShippingNote.getVehicleId();
        if (StrUtil.isEmpty(driverId)) {
            return Result.error("当前运单司机信息不存在");
        }

        if (StrUtil.isEmpty(vehicleId)) {
            return Result.error("当前运单车辆信息不存在");
        }

        boolean bDriverUploadStatus = this.hyDriverReportService.checkUploadStatus(driverId, hyShippingNote.getCompanyId(),
                ReportPlatformEnum.REPORT_PLATFORM_HB.getCode());
        if (!bDriverUploadStatus) {
            log.warn("司机未上报河北监管，开始同步司机数据, {}", driverId);
            Result dResult = this.reportDriver(driverId, hyShippingNote.getCompanyId());
            if (!dResult.getCode().equals(CommonConstant.SC_OK_200)) {
                return dResult;
            }
        }

        boolean bVehicleUploadStatus = this.vehicleReportService.checkUploadStatus(vehicleId, hyShippingNote.getCompanyId(),
                ReportPlatformEnum.REPORT_PLATFORM_HB.getCode());
        if (!bVehicleUploadStatus) {
            log.warn("车辆未上报河北监管，开始同步车辆数据, {}", vehicleId);
            Result vResult = this.reportVehicle(vehicleId, hyShippingNote.getCompanyId());
            if (!vResult.getCode().equals(CommonConstant.SC_OK_200)) {
                return vResult;
            }
        }

        return Result.OK();
    }


    public Result uploadCapitalFlow(String shippingId){

        QueryWrapper queryWrapper = new QueryWrapper();
        queryWrapper.eq("shipping_id", shippingId);
        List<HyShippingNoteBill> shippingNoteBills = hyShippingNoteBillService.list(queryWrapper);

        if(CollectionUtils.isEmpty(shippingNoteBills)) {
            throw new JeecgBootException("未找到对应数据");
        }

        HyShippingNote hyShippingNote = hyShippingNoteService.getById(shippingId);
        if (!hyShippingNote.getShippingPayStatus().equals(ShippingPayStatus.支付完成.getValue())) {
            return Result.error("该运单未支付完成");
        }

        FinancialDTO financialDTO = baseReportService.getFinancialDTO(shippingNoteBills,hyShippingNote);
        String jsonString = JSONObject.toJSONString(financialDTO);

        String reporDocType = ReportDocTypeEnum.REPORT_DOC_TYPE_WLHY_ZJ.getCode();
        ReportDocTypeEnum reportDocTypeEnum = ReportDocTypeEnum.getReportDocTypeEnumByVal(reporDocType);
        try {
            String reportResult = hbReportPlatformService.sendReport(reportDocTypeEnum, jsonString);
            if (StringUtils.isNotEmpty(reportResult)) {
                R result = JSON.parseObject(reportResult, R.class);
                boolean res =  result.getCode() == 1001 && result.isSuccess() ?  true : false;
                for (HyShippingNoteBill shippingNoteBillDb :  shippingNoteBills) {
                    shippingNoteBillDb.setUploadStatus(res ?  "1" : "2");
                    shippingNoteBillDb.setReportFailureReason(res ?  "" : result.getMsg() + result.getData());
                    shippingNoteBillDb.setUploadDate(new Date());
                    shippingNoteBillDb.setReportPlatformType(ReportPlatformEnum.REPORT_PLATFORM_HB.getCode());
                }

                hyShippingNoteBillService.updateBatchById(shippingNoteBills);
                return res ? Result.OK("上报成功") : Result.error(result.getMsg());
            }
        } catch (Exception e) {
            for(HyShippingNoteBill shippingNoteBillDb :  shippingNoteBills){
                shippingNoteBillDb.setUploadStatus("2");
                shippingNoteBillDb.setReportFailureReason(e.getMessage());
                shippingNoteBillDb.setUploadDate(new Date());
                shippingNoteBillDb.setReportPlatformType(ReportPlatformEnum.REPORT_PLATFORM_HB.getCode());
            }
            hyShippingNoteBillService.updateBatchById(shippingNoteBills);
        }

        return Result.error("上传资金流水数据失败");
    }


    /**
     * 河北省平台上报电子运单
     *
     * @param hyShippingNote
     * @return
     */
    public Result uploadShippingNote(HyShippingNote hyShippingNote) {
        HyShippingNote ShippingNoteDb = hyShippingNoteService.getById(hyShippingNote.getId());
        if (ShippingNoteDb == null) {
            throw new JeecgBootException("未找到对应数据");
        }

        if("1".equals(hyShippingNote.getUploadStatus())) {
            return Result.OK("该运单已上传");
        }

        if (!hyShippingNote.getShippingPayStatus().equals(ShippingPayStatus.支付完成.getValue())) {
            return Result.error("该运单未支付完成");
        }

        Result r = this.uploadLocation(ShippingNoteDb);
        if (!r.getCode().equals(CommonConstant.SC_OK_200)) {
            return r;
        }

        ShippingNoteDTO shippingNoteDTO = baseReportService.shippingNoteTOShippingNoteDTO(ShippingNoteDb, hyShippingNote.getCompanyId());
        String jsonString = JSONObject.toJSONString(shippingNoteDTO);
        String reporDocType = ReportDocTypeEnum.REPORT_DOC_TYPE_WLHY_YD.getCode();
        ReportDocTypeEnum reportDocTypeEnum = ReportDocTypeEnum.getReportDocTypeEnumByVal(reporDocType);

        try {
            String reportResult = hbReportPlatformService.sendReport(reportDocTypeEnum, jsonString);
            if (StringUtils.isNotEmpty(reportResult)) {
                R result = JSON.parseObject(reportResult, R.class);
                boolean  res = result.getCode() == 1001 && result.isSuccess() ? true : false;
                ShippingNoteDb.setUploadStatus(res ? "1" : "2");
                ShippingNoteDb.setReportFailureReason(res ? "" : result.getMsg() + result.getData());
                ShippingNoteDb.setUploadDate(new Date());
                ShippingNoteDb.setReportPlatformType(ReportPlatformEnum.REPORT_PLATFORM_HB.getCode());
                hyShippingNoteService.updateById(ShippingNoteDb);
                return res ? Result.OK("上报成功") : Result.error(result.getMsg());
            } else {
                throw new JeecgBootException("未知异常");
            }
        } catch (Exception e) {
            ShippingNoteDb.setUploadStatus("2");
            ShippingNoteDb.setReportFailureReason(e.getMessage());
            ShippingNoteDb.setUploadDate(new Date());
            ShippingNoteDb.setReportPlatformType(ReportPlatformEnum.REPORT_PLATFORM_HB.getCode());
            hyShippingNoteService.updateById(ShippingNoteDb);
        }

        return Result.error("上报运单数据失败");
    }

    /**
     * 河北省平台司机上报
     *
     * @param driverId
     * @return
     */
    @Override
    public Result reportDriver(String driverId, String companyId) {
        HyDriver hyDriverDb = driverService.getById(driverId);
        if (hyDriverDb == null) {
            throw new JeecgBootException("未找到对应数据");
        }

        HyDriverReport hyDriverReport = new HyDriverReport();
        //人员从业资格证验证
        if (!driverService.checkQualificationV2(hyDriverDb)) {
            throw new JeecgBootException("人员从业资格证验证号不正确或者已过期，请修改后重新上传！");
        }

        DriverDTO driverDTO = baseReportService.hyDriverTODriverDTO(hyDriverDb);
        String jsonString = JSONObject.toJSONString(driverDTO);
        String reporDocType = ReportDocTypeEnum.REPORT_DOC_TYPE_WLHY_JSY.getCode();
        ReportDocTypeEnum reportDocTypeEnum = ReportDocTypeEnum.getReportDocTypeEnumByVal(reporDocType);

        try {
            String reportResult = hbReportPlatformService.sendReport(reportDocTypeEnum, jsonString);
            if (StringUtils.isNotEmpty(reportResult)) {
                R result = JSON.parseObject(reportResult, R.class);
                boolean res = result.getCode() == 1001 && result.isSuccess() ? true : false;
                hyDriverReport.setDriverId(driverId);
                hyDriverReport.setReportPlatformType(ReportPlatformEnum.REPORT_PLATFORM_HB.getCode());
                hyDriverReport.setDriverUploadStatus(res ? "1" : "2");
                hyDriverReport.setUploadDate(new Date());
                hyDriverReport.setDriverReportFailureReason(result.getMsg() + result.getData());
                hyDriverReport.setCompanyId(companyId);
                hyDriverReportService.saveDriverReport(hyDriverReport);

                boolean bUpdate = this.driverService.updateHbUploadStatusById(driverId, "1");
                log.info("更新河北上报司机状态, {}, {}", hyDriverDb.getDriverName(), bUpdate);
                return res ? Result.OK("上报成功") : Result.error(result.getMsg());
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
        return Result.error("上报司机数据失败");
    }

    @Override
    public Result reportVehicle(String vehicleId, String companyId) {
        HyVehicle hyVehiclDb = vehicleService.getById(vehicleId);
        if (hyVehiclDb == null) {
            throw new JeecgBootException("未找到对应数据");
        }
        //if(vehicleReportService.checkUploadStatus(vehicleId , ReportPlatformEnum.REPORT_PLATFORM_HB.getCode())  ) {
        //    throw new JeecgBootException("该车辆已经上传过，请勿重复上传");
        //}
        HyVehicleReport hyVehicleReport = new HyVehicleReport();

        if (StringUtils.isEmpty(hyVehiclDb.getRoadTransportNumber())) {
            throw new JeecgBootException("车辆道路运输证不能为空！");
        }

        if (hyVehiclDb.getVehicleTonnage().compareTo(hyVehiclDb.getGrossMass()) > -1) {
            throw new JeecgBootException("车辆总质量必须大于核定载质量");
        }

        if (!vehicleService.checkRTCNoV2(hyVehiclDb)) {
            throw new JeecgBootException("车辆道路运输证号不正确或者已过期，请修改后重新上传！");
        }
        HyVehicleType hyVehicleType = vehicleService.getHyVehicleType(hyVehiclDb.getVehicleType());
        if (hyVehicleType == null) {
            throw new JeecgBootException("车辆类型不存在,修改后请重新上报！");
        }
        hyVehiclDb.setVehicleType(hyVehicleType.getValue());
        VehicleDTO vehicleDTO = baseReportService.hyVehicleDTOTOVehicleDTO(hyVehiclDb);
        String jsonString = JSONObject.toJSONString(vehicleDTO);
        String reporDocType = ReportDocTypeEnum.REPORT_DOC_TYPE_WLHY_CL.getCode();
        ReportDocTypeEnum reportDocTypeEnum = ReportDocTypeEnum.getReportDocTypeEnumByVal(reporDocType);

        try {
            String reportResult = hbReportPlatformService.sendReport(reportDocTypeEnum, jsonString);
            if (StringUtils.isNotEmpty(reportResult)) {
                R result = JSON.parseObject(reportResult, R.class);
                boolean res = result.getCode() == 1001 && result.isSuccess() ? true : false;
                hyVehicleReport.setVehicleId(vehicleId);
                hyVehicleReport.setReportPlatformType(ReportPlatformEnum.REPORT_PLATFORM_HB.getCode());
                hyVehicleReport.setVehicleUploadStatus(res ? "1" : "2");
                hyVehicleReport.setUploadDate(new Date());
                hyVehicleReport.setVehicleReportFailureReason(result.getMsg() + result.getData());
                hyVehicleReport.setCompanyId(companyId);
                vehicleReportService.saveVehicleReport(hyVehicleReport);

                boolean bUpdate = this.vehicleService.updateHbUploadStatusById(vehicleId, "1");
                log.info("更新河北上报车辆状态, {}, {}", hyVehiclDb.getVehicleNumber(), bUpdate);
                return res ? Result.OK("上报成功") : Result.error(result.getMsg());
            }
        } catch (Exception e) {
            e.printStackTrace();
            log.error("上报车辆数据失败, {}", e.getMessage());
        }

        return Result.error("上报车辆数据失败");
    }


    /**
     * (新)河北驾驶员位置信息
     * 通过此接口，在运单起运和确认送达时，经驾驶员授权同意后，实时采集和上传驾驶员地理位置信息。
     * @param hyShippingNote
     */
    public Result uploadLocation(HyShippingNote hyShippingNote) {

        log.info("上报运单位置信息--------------------------------------1");
        String reporDocType = ReportDocTypeEnum.REPORT_DOC_TYPE_WLHY_WZ.getCode();
        ReportDocTypeEnum reportDocTypeEnum = ReportDocTypeEnum.getReportDocTypeEnumByVal(reporDocType);

        try {
            if (null == hyShippingNote.getSendLatitude() || null == hyShippingNote.getSendLongitude()) {
                return Result.error("发货地址经纬度不能为空");
            }

            if (null == hyShippingNote.getReceiveLatitude() || null == hyShippingNote.getReceiveLongitude()) {
                return Result.error("发货地址经纬度不能为空");
            }

            double[] sendLngLon = LngLonUtil.bd09_To_gps84(hyShippingNote.getSendLatitude().doubleValue(), hyShippingNote.getSendLongitude().doubleValue());
            double[] receivedLngLon = LngLonUtil.bd09_To_gps84(hyShippingNote.getReceiveLatitude().doubleValue(), hyShippingNote.getReceiveLongitude().doubleValue());

            //发货
            LocationDTO sendLocationDTO = new LocationDTO();
            sendLocationDTO.setSendToProDateTime(DateUtils.dateToStringDateTime(new Date()));
            sendLocationDTO.setShippingNoteNumber(hyShippingNote.getShippingNoteNumber());

            sendLocationDTO.setLocationType(0);
            sendLocationDTO.setSendDateTime(DateUtils.dateToStringDateTime(hyShippingNote.getStatusDtLoading()));
            sendLocationDTO.setLatitude(String.valueOf((new BigDecimal(sendLngLon[0])).multiply(new BigDecimal(1000000)).longValue()));
            sendLocationDTO.setLongitude(String.valueOf((new BigDecimal(sendLngLon[1])).multiply(new BigDecimal(1000000)).longValue()));
            sendLocationDTO.setCountrySubdivisionCode(hyShippingNote.getSendAreaCode());
            sendLocationDTO.setLocationText(hyShippingNote.getSendAddress());
            String sendResult = this.hbReportPlatformService.sendReport(reportDocTypeEnum, JSONUtil.toJsonStr(sendLocationDTO));
            if (StrUtil.isEmpty(sendResult)) {
                return Result.error("上传发货位置信息失败");
            }

            log.info("上报运单位置信息--------------------------------------2");
            R r1 = JSON.parseObject(sendResult, R.class);
            boolean res1 = r1.getCode() == 1001 ? true : false;
            if (!res1 && !r1.getMsg().contains("重复")) {
                return Result.error(r1.getMsg());
            }

            //收货
            LocationDTO receiveLocationDTO = new LocationDTO();
            receiveLocationDTO.setSendToProDateTime(DateUtils.dateToStringDateTime(new Date()));
            receiveLocationDTO.setShippingNoteNumber(hyShippingNote.getShippingNoteNumber());

            receiveLocationDTO.setLocationType(1);
            receiveLocationDTO.setSendDateTime(DateUtils.dateToStringDateTime(hyShippingNote.getStatusDtUnloading()));
            receiveLocationDTO.setLatitude(String.valueOf((new BigDecimal(receivedLngLon[0])).multiply(new BigDecimal(1000000)).longValue()));
            receiveLocationDTO.setLongitude(String.valueOf((new BigDecimal(receivedLngLon[1])).multiply(new BigDecimal(1000000)).longValue()));
            receiveLocationDTO.setCountrySubdivisionCode(hyShippingNote.getReceiveAreaCode());
            receiveLocationDTO.setLocationText(hyShippingNote.getReceiveAddress());
            String recvResult = this.hbReportPlatformService.sendReport(reportDocTypeEnum, JSONUtil.toJsonStr(receiveLocationDTO));
            if (StrUtil.isEmpty(recvResult)) {
                return Result.error("上传收货位置信息失败");
            }

            R r2 = JSON.parseObject(sendResult, R.class);
            boolean res2 = r2.getCode() == 1001 ? true : false;
            if (!res2 && !r2.getMsg().contains("重复")) {
                return Result.error(r2.getMsg());
            }

            log.info("上报运单位置信息--------------------------------------3");
        } catch (Exception e) {
            log.error("上报河北监管运单位置信息异常:{}", e.getMessage());
        }

        return Result.OK();
    }

    /**
     * 河北省平台上报企业信息
     * @param actionType 操作类型  1:新增操作 2：更新操作
     * @return
     */
    public Result uploadEnterprise(String actionType) {

        HyEnterprise hyEnterprise = enterpriseService.queryTopData();
        if (null == hyEnterprise) {
            return Result.error("上报企业信息不存在");
        }

        EnterpriseDTO enterpriseDTO = baseReportService.getEnterpriseDTO(hyEnterprise, actionType);
        String jsonString = JSONObject.toJSONString(enterpriseDTO);

        String reporDocType = ReportDocTypeEnum.REPORT_DOC_TYPE_WLHY_QY.getCode();
        ReportDocTypeEnum reportDocTypeEnum = ReportDocTypeEnum
                .getReportDocTypeEnumByVal(reporDocType);

        try {
            String reportResult = hbReportPlatformService.sendReport(reportDocTypeEnum,jsonString);
            if (StringUtils.isNotEmpty(reportResult)) {
                R result = JSON.parseObject(reportResult, R.class);
                return result.getCode() == 1001 ? Result.OK("上传成功") : Result.error("上报失败,原因: " + result.getMsg());
            }
        } catch (Exception e) {
            log.error("上传河北监管公司信息失败, {}", e.getMessage());
        }

        return Result.error("上报企业信息时发生错误");
    }


    //region 模拟运单及资金流水数据上报
    @Override
    public Result reportTestShippingNote(String json) {

        String jsonString = json;
        String reporDocType = ReportDocTypeEnum.REPORT_DOC_TYPE_WLHY_YD.getCode();
        ReportDocTypeEnum reportDocTypeEnum = ReportDocTypeEnum.getReportDocTypeEnumByVal(reporDocType);


        log.info("测试模拟分段运单上报 {}", jsonString);

        try {
            String reportResult = hbReportPlatformService.sendReport(reportDocTypeEnum, jsonString);
            if (StringUtils.isNotEmpty(reportResult)) {
                R result = JSON.parseObject(reportResult, R.class);
                return result.getCode() == 1001 ? Result.OK("上传成功") : Result.error("上报失败,原因: " + result.getMsg());
            }
        } catch (Exception e) {
            log.error("上传河北监管公司信息失败, {}", e.getMessage());
        }

        return Result.OK();
    }


    @Override
    public Result reportTestCapitalFlow(String json) {
        String jsonString = json;

        String reporDocType = ReportDocTypeEnum.REPORT_DOC_TYPE_WLHY_ZJ.getCode();
        ReportDocTypeEnum reportDocTypeEnum = ReportDocTypeEnum.getReportDocTypeEnumByVal(reporDocType);

        log.info("测试模拟分段运单上报 {}", jsonString);
        try {
            String reportResult = hbReportPlatformService.sendReport(reportDocTypeEnum, jsonString);
            if (StringUtils.isNotEmpty(reportResult)) {
                R result = JSON.parseObject(reportResult, R.class);
                return result.getCode() == 1001 ? Result.OK("上传成功") : Result.error("上报失败,原因: " + result.getMsg());
            }
        } catch (Exception e) {
            log.error("上传河北监管公司信息失败, {}", e.getMessage());
        }

        return Result.OK();
    }
    //endregion

}
